from rest_framework import serializers

from apps.goods.models import GoodsChannel, GoodsCategory, GoodsChannelGroup


class GoodsChannelSerializer(serializers.ModelSerializer):
    '''
        商品频道表序列化器
    '''
    # 返回分类名
    group = serializers.StringRelatedField(read_only=True)
    # 返回组id
    group_id = serializers.IntegerField()
    # 返回分类数据
    category = serializers.StringRelatedField(read_only=True)
    # 返回一级分类id
    category_id = serializers.IntegerField()
    # 返回组名
    category_name = serializers.StringRelatedField(read_only=True)

    class Meta:
        # 指定模型类
        model = GoodsChannel
        fields = '__all__'


class GoodsCategorySerializer(serializers.ModelSerializer):
    '''
        商品类别序列化器
    '''
    class Meta:
        model = GoodsCategory
        fields = '__all__'


class GoodsChannelGroupSerializer(serializers.ModelSerializer):
    '''
        商品频道组序列化器
    '''
    class Meta:
        model = GoodsChannelGroup
        fields = '__all__'
